const { User } = require("../../models/user");

module.exports = async (req, res) => {
  
  req.app.locals.currentLink = 'user';
  
  const { message, id } = req.query;
  // 如果传递了id，则为修改操作
  if (id) {
    // 修改操作
    const user = await User.findOne({ _id: id });
    res.render("admin/user-edit", {
      message,
      user,
      link: '/admin/user-modify?id=' + id, // 修改
      button: '修改',
    });
  } else {
    // 添加操作
    res.render("admin/user-edit", {
        message,
        link: '/admin/user-edit',
        button: '添加'
    })
  }
};
